package logic

import (
	"context"
	"fmt"
	"home/models"

	"home/homerpc/homerpc"
	"home/homerpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type FurnishedShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewFurnishedShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FurnishedShowLogic {
	return &FurnishedShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 详情
func (l *FurnishedShowLogic) FurnishedShow(in *homerpc.FurnishedShowRequest) (*homerpc.FurnishedShowResponse, error) {
	// todo: add your logic here and delete this line

	var furnished models.Furnished
	models.DB.Debug().Where("id = ?", in.FurnishedId).Find(&furnished)
	if furnished.ID == 0 {
		return nil, fmt.Errorf("当前商品详情不存在")
	}

	return &homerpc.FurnishedShowResponse{
		Name:        furnished.Name,
		Price:       float32(furnished.Price),
		ClassName:   furnished.ClassName,
		BrandName:   furnished.BrandName,
		FurnishedId: int64(furnished.ID),
	}, nil
}
